package sky.cin.framework.network.filter;

import sky.cin.framework.network.dto.HttpServletRequest;
import sky.cin.framework.network.dto.HttpServletResponse;

public abstract class Filter {

    private static Filter head;
    private Filter next;

    protected static int count = 1;

    public static void add(Filter filter) {
        if (head == null) {
            head = new FinalFilter();
        }
        filter.next = head;
        head = filter;
        count++;
    }

    public static boolean start(HttpServletRequest request, HttpServletResponse response) {
        if (head == null) {
            head = new FinalFilter();
        }
        return head.doFilter(request, response);
    }

    abstract public boolean doFilter(HttpServletRequest request, HttpServletResponse response);

    public boolean next(HttpServletRequest request, HttpServletResponse response) {
        return next.doFilter(request, response);
    }

}
